package controller

import (
	"net/http"

	"EREST/service"
	log "git.edaijia-inc.cn/edaijia/ego/elogger"

	"github.com/gin-gonic/gin"
)

type DemoReq struct {
	Param1 string `form:"p1" json:"p1" binding:"required"`
	Param2 int32  `form:"p2" json:"p2" binding:"required"`
}

type DemoResp struct {
	Res1 string `json:"r1"`
	Res2 int32  `json:"r2"`
}

// @Summary 演示接口
// @Description 演示
// @Param Param1 query string true "参数1"
// @Param Param2 query int true "参数2"
// @Success 200 {string} string
// @Router /demo [get]
func Demo(c *gin.Context) {
	log.Debug("func Demo")

	var demoReq DemoReq
	if err := c.ShouldBindQuery(&demoReq); err != nil {
		c.JSON(http.StatusOK, FailParamResp())
		return
	}

	demo, err := service.Demo(c, demoReq.Param1, demoReq.Param2)
	if err != nil {
		c.JSON(http.StatusOK, FailServerResp())
		return
	}

	resp := DemoResp{Res1: demo.Name, Res2: demo.Age}
	c.JSON(http.StatusOK, SuccResp("请求成功", resp))
}
